﻿using Infrastructure;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using SnowTech.SmartTms.App;
using SnowTech.SmartTms.App.Interface;
using SnowTech.SmartTms.App.Vehicle;
using SnowTech.SmartTms.App.Vehicle.Request;
using System;
using System.Threading.Tasks;

namespace SnowTech.SmartTms.Mvc.Controllers
{
    public class TmsVehicleController : BaseController
    {
        private readonly VehicleApp _app;
        

        public TmsVehicleController(IAuth authUtil, VehicleApp app) : base(authUtil)
        {
            _app = app;
        }
        public IActionResult Index()
        {
            return View();
        }

        [HttpGet]
        public string Load([FromQuery] VehicleShowReq request)
        {
            var objs = _app.VehicleLoad(request);
            return JsonHelper.Instance.Serialize(objs);
        }
        /// <summary>
        /// 车辆删除
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>
        [HttpPost]
        public string Delete(string[] ids)
        {
            Response resp = new Response();
            try
            {
                _app.VehicleDel(ids);
            }
            catch (Exception e)
            {
                resp.Code = 500;
                resp.Message = e.Message;
            }
            return JsonHelper.Instance.Serialize(resp);
        }
        /// <summary>
        /// 车辆数据添加
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        [HttpPost]
        public string Add(VehicleAppReq obj)
        {
            Response resp = new Response();
            try
            {
                _app.VehicleAdd(obj);
            }
            catch (Exception e)
            {
                resp.Code = 500;
                resp.Message = e.Message;
            }
            return JsonHelper.Instance.Serialize(resp);
        }
        /// <summary>
        /// 车辆更新
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        [HttpPost]
        public string Update(VehicleAppReq obj)
        {
            Response resp = new Response();
            try
            {
                _app.VehicleUpt(obj);
            }
            catch (Exception e)
            {
                resp.Code = 500;
                resp.Message = e.Message;
            }
            return JsonHelper.Instance.Serialize(resp);
        }
    }
}
